home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WINSRC20.ZIP / WINDOS.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  27KB  |  910 lines

  1. /*
  2.     Routines which simulate DOS functions in the existing
  3.     Fractint for DOS
  4. */
  5.  
  6. #include "windows.h"
  7. #include "fractint.h"
  8. #include "winfract.h"
  9. #include <time.h>
  10. #include <stdio.h>
  11.  
  12. int save_system;           /* tag identifying Fractint for Windows */
  13. int save_release;          /* tag identifying version number */
  14. int win_release = 200;     /* tag identifying version number */
  15. char win_comment[] =       /* "About..." comment */ 
  16.     {" "};                 /*  publicly-released version */
  17. /*  {"Test Version - Not for Release"};   interim test versions */
  18.  
  19. extern BOOL bTrack;                  /* TRUE if user is selecting a region */
  20. extern BOOL zoomflag;                /* TRUE is a zoom-box selected */
  21.  
  22. extern HWND hwnd;                    /* handle to main window */
  23.  
  24. extern int xdots, ydots, colors, maxiter;
  25. extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  26. extern int win_xdots, win_ydots;
  27.  
  28. extern int last_written_y;           /* last line written */
  29. extern int screen_to_be_cleared;     /* clear screen flag */
  30.  
  31. extern int time_to_act;              /* time to take some action? */
  32. extern int time_to_restart;          /* time to restart?  */
  33. extern int time_to_quit;             /* time to quit? */
  34. extern int time_to_reinit;           /* time to reinitialize? */
  35. extern int time_to_load;             /* time to load? (DECODE) */
  36. extern int time_to_save;             /* time to save? (ENCODE) */
  37. extern int time_to_print;            /* time to print? (PRINTER) */
  38. extern int time_to_cycle;            /* time to begin color-cycling? */
  39.  
  40. extern unsigned char dacbox[256][3];
  41.  
  42. extern BOOL win_systempaletteused;    /* flag system palette set */
  43.  
  44. extern unsigned char far temp_array[];   /* temporary spot for Encoder rtns */
  45.  
  46. extern HANDLE hpixels;            /* handle to the DIB pixels */
  47. extern unsigned char huge *pixels;   /* the device-independent bitmap pixels */
  48. int pixels_per_byte;                 /* pixels/byte in the pixmap */
  49. long pixels_per_bytem1;              /* pixels / byte - 1 (for ANDing) */
  50. int pixelshift_per_byte;             /* 0, 1, 2, or 3 */
  51. int bytes_per_pixelline;             /* pixels/line / pixels/byte */
  52.  
  53. extern int kbdcount;
  54.  
  55. extern int win_overlay3d;
  56. extern int win_display3d;
  57.  
  58. /****************************************************************************
  59.  
  60.     FUNCTION: keypressed(), getakey()
  61.  
  62.     PURPOSE:
  63.          keypressed()
  64.               Checks for, and processes, messages.
  65.               Returns -1 if it's time to wrap up and go home.
  66.               Returns 0 otherwise.
  67.         getakey()
  68.               same, but doesn't return until it's time to.
  69.  
  70.  
  71. ****************************************************************************/
  72.  
  73. BOOL dont_wait_for_a_key = TRUE;
  74.  
  75. int getakey()
  76. {
  77. int i;
  78.  
  79. dont_wait_for_a_key = FALSE;
  80. i = keypressed();
  81. dont_wait_for_a_key = TRUE;
  82. zoomflag = FALSE;
  83. return(i);
  84.  
  85. }
  86.  
  87. int keypressed()
  88. {
  89. MSG msg;
  90.  
  91. if (dont_wait_for_a_key)
  92.     if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
  93.         time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  94.             time_to_load+time_to_save+time_to_print+time_to_cycle;
  95.         /* bail out if nothing is happening */
  96.         return(time_to_act);
  97.         }
  98.  
  99. while (GetMessage(&msg, NULL, NULL, NULL)) {
  100.  
  101.     TranslateMessage(&msg);
  102.     DispatchMessage(&msg); 
  103.  
  104.     if (!bTrack) {                /* don't do this if mouse-button is down */
  105.         time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  106.             time_to_load+time_to_save+time_to_print+time_to_cycle;
  107.         if (dont_wait_for_a_key || time_to_act)
  108.             return(time_to_act);
  109.         }
  110.  
  111.     }
  112.  
  113. if (!dont_wait_for_a_key)
  114.     time_to_quit = 1;
  115.         
  116.     /* bail out if nothing is happening */
  117.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  118.         time_to_load+time_to_save+time_to_print+time_to_cycle;
  119.     return(time_to_act);
  120.  
  121. }
  122.  
  123. /****************************************************************************
  124.  
  125.     FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
  126.  
  127.     PURPOSE:
  128.         putcolor:
  129.            sets the "color" value of the pixel at location x,y
  130.            (actually, a palette value)
  131.         getcolor:
  132.            returns the "color" value of the pixel at location x,y
  133.            (actually, a palette value)
  134.  
  135. ****************************************************************************/
  136.  
  137. extern int debug_fastupdate;
  138.  
  139. time_t last_time;
  140. time_t update_time;
  141. long minimum_update;
  142. long pixelsout;
  143. int top_changed, bottom_changed;
  144.  
  145. static unsigned char win_andmask[8];
  146. static unsigned char win_notmask[8];
  147. static unsigned char win_bitshift[8];
  148.  
  149. void putcolor(int x, int y, int color)
  150. {
  151. RECT tempRect;                   /* temporary rectangle structure */
  152. long i;
  153. int j, tempcolor, temp_top_changed, temp_bottom_changed;
  154. time_t this_time;
  155.  
  156. kbdcount--;      /* partially adjust for the lower speed of Win graphics */
  157.  
  158. last_written_y = y;
  159. if (y < top_changed) top_changed = y;
  160. if (y > bottom_changed) bottom_changed = y;
  161.  
  162. i = win_ydots-1-y;
  163. i = (i * win_xdots) + x;
  164.  
  165. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  166.     if (pixelshift_per_byte == 0) {
  167.           pixels[i] = color % colors;
  168.           }
  169.      else {
  170.           unsigned int j;
  171.           j = i & pixels_per_bytem1;
  172.           i = i >> pixelshift_per_byte;
  173.           pixels[i] = (pixels[i] & win_notmask[j]) +
  174.               (((unsigned char)(color % colors)) << win_bitshift[j]);
  175.           }
  176.  
  177.      /* check the time every nnn pixels */
  178.      if (debug_fastupdate || ++pixelsout > 100) {
  179.           pixelsout = 0;
  180.           this_time = time(NULL);
  181.           /* time to update the screen? */
  182.           if (debug_fastupdate || (this_time - last_time) > update_time ||
  183.               (minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
  184.               temp_top_changed = top_changed - win_yoffset;
  185.               temp_bottom_changed = bottom_changed - win_yoffset;
  186.               if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
  187.                   if (temp_top_changed < 0) temp_top_changed = 0;
  188.                   if (temp_bottom_changed < 0) temp_bottom_changed = 0;
  189.                   tempRect.top = temp_top_changed;
  190.                   tempRect.bottom = temp_bottom_changed+1;
  191.                   tempRect.left = 0;
  192.                   tempRect.right = xdots;
  193.                   InvalidateRect(hwnd, &tempRect, FALSE);
  194.                   keypressed();    /* force a look-see at the screen */
  195.                   }
  196.               last_time = this_time;
  197.               top_changed = win_ydots;
  198.               bottom_changed = 0;
  199.               }
  200.           }
  201.      }
  202.  
  203. }
  204.  
  205. int getcolor(int x, int y)
  206. {
  207. long i;
  208.  
  209. i = win_ydots-1-y;
  210. i = (i * win_xdots) + x;
  211.  
  212. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  213.     if (pixelshift_per_byte == 0) {
  214.           return(pixels[i]);
  215.           }
  216.      else {
  217.           unsigned int j;
  218.           j = i & pixels_per_bytem1;
  219.           i = i >> pixelshift_per_byte;
  220.           return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
  221.           }
  222.      }
  223. else
  224.      return(0);
  225. }
  226.  
  227. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  228. {
  229. int i, len;
  230. long startloc;
  231.  
  232. len = rightpt - leftpt;
  233. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  234. startloc = win_ydots-1-rownum;
  235. startloc = (startloc * win_xdots) + leftpt;
  236.  
  237. kbdcount -= (len>>2);      /* adjust for the lower speed of Win graphics */
  238.  
  239. if (rownum < 0 || rownum >= ydots || leftpt < 0) {
  240.     return(0);
  241.     }
  242.  
  243. if (pixelshift_per_byte == 0) {
  244.     for (i = 0; i <= len; i++)
  245.         pixels[startloc+i] = localvalues[i];
  246.     }
  247. else {
  248.     unsigned int j;
  249.     long k;
  250.     for (i = 0; i <= len; i++) {
  251.         k = startloc + i;
  252.         j = k & pixels_per_bytem1;
  253.         k = k >> pixelshift_per_byte;
  254.         pixels[k] = (pixels[k] & win_notmask[j]) +
  255.             (((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
  256.         }
  257.     }
  258. pixelsout += len;
  259. putcolor(leftpt, rown